package cn.dugcrs.basic.service.impl;

import cn.dugcrs.basic.mapper.BaseMapper;
import cn.dugcrs.basic.query.BaseQuery;
import cn.dugcrs.basic.service.IBaseService;
import cn.dugcrs.basic.utils.QueryResult;
import cn.dugcrs.org.domain.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;

    /**
    * @Title: queryPage
    * @Description: 分页、高级查询
    * @Author: Gubcog
    * @Version: 1.0
    * @Date:  2022/4/25 16:00
    * @Parameters: * @param baseQuery
    * @Return cn.dugcrs.basic.utils.QueryResult<T>
    */
    @Override
    public QueryResult<T> queryPage(BaseQuery baseQuery) {
        Integer total = baseMapper.queryCount(baseQuery);
        List<T> rows = baseMapper.queryPage(baseQuery);
//        System.out.println(total);
//        System.out.println(rows);
        return new QueryResult(total,rows);
    }

    @Override
    public T loadById(Long id) {
        return  baseMapper.loadById(id);
    }


    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        baseMapper.remove(id);
    }

    @Override
    @Transactional
    public void batchRemove(List<Long> ids) {
        baseMapper.batchRemove(ids);
    }

    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }
}
